package org.dothwinds.serviceconsumer.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.dothwinds.serviceconsumer.serviceinterface.ServiceConsumerInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ServiceConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ServiceConsumerInterface serviceConsumerInterface;

    @GetMapping("/testLoadBalance")
    @HystrixCommand(fallbackMethod = "error")
    public String serviceCousumer(){
//       return restTemplate.getForObject("http://SERVICE-PROVIDER/service", String.class);
        return serviceConsumerInterface.serviceCousumer();
    }

    public String error(){
        return "Hystrix生效了，没有调用到服务，直接返回错误信息了~~";
    }
}
